Skip to content

fix: forward process.stdin to child when no explicit input is provided#1420

Open
fresh3nough wants to merge 2 commits intogoogle:mainfrom
fresh3nough:fix/stdin-inheritance
Open

fix: forward process.stdin to child when no explicit input is provided#1420
fresh3nough wants to merge 2 commits intogoogle:mainfrom
fresh3nough:fix/stdin-inheritance

Conversation

@fresh3nough
Copy link
Contributor

Fixes #1378

When using $cat`` or any interactive command via zx's $, the child process's stdin was not connected to the parent's stdin. This meant interactive commands could not read from the terminal, unlike standard shell behavior.

Root cause

The default stdio is 'pipe', which creates a new pipe for stdin. However, nothing connected process.stdin to the child's stdin pipe -- the child received an empty VoidStream instead.

Fix

In the ProcessPromise.run() method's start handler, after the child process spawns, process.stdin is now piped to child.stdin when all of the following conditions are met:

  • No explicit $.input is provided
  • The process is not running synchronously
  • child.stdin exists and is not destroyed (stdio[0] is 'pipe')
  • process.stdin is readable and has not ended
  • The process is not receiving piped input from another ProcessPromise

Cleanup is handled automatically: errors on child.stdin are suppressed via a noop handler, and process.stdin is unpiped when the child closes.

How to reproduce

#!/usr/bin/env zx

await $`cat`

Run the script, type something, press Enter -- previously nothing happened. Now it echoes input and responds to Ctrl+D (EOF) as expected.

Tests

  • Added integration test: spawns a child Node.js process running $cat``, writes to its stdin, and verifies the output is forwarded correctly.

  • All 28 existing stdin and pipe tests continue to pass.

  • Setup Set the latest Node.js LTS version.

  • Build: I've run npm build before committing and verified the bundle updates correctly.

  • Tests: I've run test and confirmed all tests succeed. Added tests to cover my changes if needed.

  • Docs: I've added or updated relevant documentation as needed.

  • Sign Commits have verified signatures and follow conventional commits spec

  • CoC: My changes follow the project's coding guidelines and Code of Conduct.

  • Review: This PR represents original work and is not solely generated by AI tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Interactive prompting does not work

1 participant